using HKB.Common;
using HKB.Data.Dal;
using HKB.Data.Model;
using System;
using System.Collections.Generic;
using System.Data;
namespace HKB.Data.Bll
{
	public class AccountAoucher
	{
		private readonly HKB.Data.Dal.AccountAoucher dal = new HKB.Data.Dal.AccountAoucher();
		public int GetMaxId()
		{
			return this.dal.GetMaxId();
		}
		public bool Exists(int AccountAoucherID)
		{
			return this.dal.Exists(AccountAoucherID);
		}
		public int Add(HKB.Data.Model.AccountAoucher model)
		{
			return this.dal.Add(model);
		}
		public int AddTransaction(HKB.Data.Model.AccountAoucher model, Conn conn)
		{
			return this.dal.AddTransaction(model, conn);
		}
		public bool Update(HKB.Data.Model.AccountAoucher model)
		{
			return this.dal.Update(model);
		}
		public bool Delete(int AccountAoucherID)
		{
			return this.dal.Delete(AccountAoucherID);
		}
		public bool DeleteList(string AccountAoucherIDlist)
		{
			return this.dal.DeleteList(AccountAoucherIDlist);
		}
		public HKB.Data.Model.AccountAoucher GetModel(int AccountAoucherID)
		{
			return this.dal.GetModel(AccountAoucherID);
		}
		public HKB.Data.Model.AccountAoucher GetModelByCache(int AccountAoucherID)
		{
			string cacheKey = "AccountAoucherModel-" + AccountAoucherID;
			object obj = DataCache.GetCache(cacheKey);
			if (obj == null)
			{
				try
				{
					obj = this.dal.GetModel(AccountAoucherID);
					if (obj != null)
					{
						int configInt = ConfigHelper.GetConfigInt("ModelCache");
						DataCache.SetCache(cacheKey, obj, System.DateTime.Now.AddMinutes((double)configInt), System.TimeSpan.Zero);
					}
				}
				catch
				{
				}
			}
			return (HKB.Data.Model.AccountAoucher)obj;
		}
		public DataSet GetList(string strWhere)
		{
			return this.dal.GetList(strWhere);
		}
		public DataSet GetList(int Top, string strWhere, string filedOrder)
		{
			return this.dal.GetList(Top, strWhere, filedOrder);
		}
		public System.Collections.Generic.List<HKB.Data.Model.AccountAoucher> GetModelList(string strWhere)
		{
			DataSet list = this.dal.GetList(strWhere);
			return this.DataTableToList(list.Tables[0]);
		}
		public System.Collections.Generic.List<HKB.Data.Model.AccountAoucher> DataTableToList(DataTable dt)
		{
			System.Collections.Generic.List<HKB.Data.Model.AccountAoucher> list = new System.Collections.Generic.List<HKB.Data.Model.AccountAoucher>();
			int count = dt.Rows.Count;
			if (count > 0)
			{
				for (int i = 0; i < count; i++)
				{
					HKB.Data.Model.AccountAoucher accountAoucher = this.dal.DataRowToModel(dt.Rows[i]);
					if (accountAoucher != null)
					{
						list.Add(accountAoucher);
					}
				}
			}
			return list;
		}
		public DataSet GetAllList()
		{
			return this.GetList("");
		}
		public int GetRecordCount(string strWhere)
		{
			return this.dal.GetRecordCount(strWhere);
		}
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
		}
		public DataTable GetListAccountAoucherItemSubjcetByAccountAoucherID(int accountAoucherID)
		{
			return this.dal.GetListAccountAoucherItemSubjcetByAccountAoucherID(accountAoucherID);
		}
		public DataTable GetListAccountAoucherItemSubjcet(string strSQLWhere)
		{
			return this.dal.GetListAccountAoucherItemSubjcet(strSQLWhere);
		}
		public DataTable GetListAccountAoucherItemSubjcetContainOwnerName(string strSQLWhere)
		{
			return this.dal.GetListAccountAoucherItemSubjcetContainOwnerName(strSQLWhere);
		}
		public int GetListAccountAoucherItemSubjcetRecordCount(string strSQLWhere)
		{
			return this.dal.GetListAccountAoucherItemSubjcetRecordCount(strSQLWhere);
		}
		public DataTable GetListAccountAoucherItemSubjcetPage(string strSQLWhere, string OrderBy, int startIndex, int endIndex)
		{
			return this.dal.GetListAccountAoucherItemSubjcetPage(strSQLWhere, OrderBy, startIndex, endIndex);
		}
		public DataSet GetNewDataSet(DataTable dtInfo, bool subjectNameSign)
		{
			DataTable dataTable = new DataTable();
			DataColumn column = new DataColumn("RowCount", typeof(string));
			dataTable.Columns.Add(column);
			DataColumn column2 = new DataColumn("AccountAoucherID", typeof(string));
			dataTable.Columns.Add(column2);
			DataColumn column3 = new DataColumn("AccountANumber", typeof(string));
			dataTable.Columns.Add(column3);
			DataColumn column4 = new DataColumn("InputDate", typeof(string));
			dataTable.Columns.Add(column4);
			DataColumn column5 = new DataColumn("UpdateDate", typeof(string));
			dataTable.Columns.Add(column5);
			DataColumn column6 = new DataColumn("StockOrderID", typeof(string));
			dataTable.Columns.Add(column6);
			DataColumn column7 = new DataColumn("AccountACount", typeof(string));
			dataTable.Columns.Add(column7);
			DataColumn column8 = new DataColumn("AccountAExplain", typeof(string));
			dataTable.Columns.Add(column8);
			DataColumn column9 = new DataColumn("Inputer", typeof(string));
			dataTable.Columns.Add(column9);
			DataColumn column10 = new DataColumn("IsCaudit", typeof(string));
			dataTable.Columns.Add(column10);
			DataColumn column11 = new DataColumn("CauditName", typeof(string));
			dataTable.Columns.Add(column11);
			DataColumn column12 = new DataColumn("CauditDate", typeof(string));
			dataTable.Columns.Add(column12);
			DataColumn column13 = new DataColumn("IsAccount", typeof(string));
			dataTable.Columns.Add(column13);
			DataColumn column14 = new DataColumn("AccountName", typeof(string));
			dataTable.Columns.Add(column14);
			DataColumn column15 = new DataColumn("AccountDate", typeof(string));
			dataTable.Columns.Add(column15);
			DataColumn column16 = new DataColumn("IsCashier", typeof(string));
			dataTable.Columns.Add(column16);
			DataColumn column17 = new DataColumn("CashierName", typeof(string));
			dataTable.Columns.Add(column17);
			DataColumn column18 = new DataColumn("CashierDate", typeof(string));
			dataTable.Columns.Add(column18);
			DataColumn column19 = new DataColumn("OwnerID", typeof(string));
			dataTable.Columns.Add(column19);
			DataColumn column20 = new DataColumn("OwnerName", typeof(string));
			dataTable.Columns.Add(column20);
			DataColumn column21 = new DataColumn("AccountAItemID", typeof(int));
			dataTable.Columns.Add(column21);
			DataColumn column22 = new DataColumn("AAItemAccountSID", typeof(int));
			dataTable.Columns.Add(column22);
			DataColumn column23 = new DataColumn("AAItemSummary", typeof(string));
			dataTable.Columns.Add(column23);
			DataColumn column24 = new DataColumn("AccountSNumber", typeof(string));
			dataTable.Columns.Add(column24);
			DataColumn column25 = new DataColumn("AccountSName", typeof(string));
			dataTable.Columns.Add(column25);
			DataColumn column26 = new DataColumn("BorrowPrice", typeof(string));
			dataTable.Columns.Add(column26);
			DataColumn column27 = new DataColumn("LoanPrice", typeof(string));
			dataTable.Columns.Add(column27);
			string a = "";
			int num = 1;
			foreach (DataRow dataRow in dtInfo.Rows)
			{
				DataRow dataRow2 = dataTable.NewRow();
				string text = dataRow["AccountAoucherID"].ToString();
				dataRow2["RowCount"] = num;
				if (a != text)
				{
					dataRow2["AccountAoucherID"] = text;
					dataRow2["AccountANumber"] = dataRow["AccountANumber"].ToString();
					dataRow2["InputDate"] = dataRow["InputDate"].ToString();
					string value = "";
					if (dtInfo.Columns.Contains("UpdateDate"))
					{
						if (dataRow["UpdateDate"] != System.DBNull.Value)
						{
							value = dataRow["UpdateDate"].ToString();
						}
					}
					dataRow2["UpdateDate"] = value;
					string value2 = "";
					if (dtInfo.Columns.Contains("StockOrderID"))
					{
						if (dataRow["StockOrderID"] != System.DBNull.Value)
						{
							value2 = dataRow["StockOrderID"].ToString();
						}
					}
					dataRow2["StockOrderID"] = value2;
					string value3 = "";
					if (dtInfo.Columns.Contains("AccountACount"))
					{
						if (dataRow["AccountACount"] != System.DBNull.Value)
						{
							value3 = dataRow["AccountACount"].ToString();
						}
					}
					dataRow2["AccountACount"] = value3;
					string value4 = "";
					if (dtInfo.Columns.Contains("AccountAExplain"))
					{
						if (dataRow["AccountAExplain"] != System.DBNull.Value)
						{
							value4 = dataRow["AccountAExplain"].ToString();
						}
					}
					dataRow2["AccountAExplain"] = value4;
					string value5 = "";
					if (dtInfo.Columns.Contains("Inputer"))
					{
						if (dataRow["Inputer"] != System.DBNull.Value)
						{
							value5 = dataRow["Inputer"].ToString();
						}
					}
					dataRow2["Inputer"] = value5;
					string a2 = "";
					if (dataRow["IsCaudit"] != System.DBNull.Value)
					{
						a2 = dataRow["IsCaudit"].ToString().ToLower().Trim();
					}
					if (a2 == "true" || a2 == "1")
					{
						dataRow2["IsCaudit"] = "<span style='color:Green;'>√</span>";
					}
					else
					{
						dataRow2["IsCaudit"] = "<span style='color:Red;'>×</span>";
					}
					string value6 = "";
					if (dtInfo.Columns.Contains("CauditName"))
					{
						if (dataRow["CauditName"] != System.DBNull.Value)
						{
							value6 = dataRow["CauditName"].ToString();
						}
					}
					dataRow2["CauditName"] = value6;
					string value7 = "";
					if (dtInfo.Columns.Contains("CauditDate"))
					{
						if (dataRow["CauditDate"] != System.DBNull.Value)
						{
							value7 = dataRow["CauditDate"].ToString();
						}
					}
					dataRow2["CauditDate"] = value7;
					string a3 = "";
					if (dataRow["IsAccount"] != System.DBNull.Value)
					{
						a3 = dataRow["IsAccount"].ToString().ToLower().Trim();
					}
					if (a3 == "true" || a3 == "1")
					{
						dataRow2["IsAccount"] = "<span style='color:Green;'>√</span>";
					}
					else
					{
						dataRow2["IsAccount"] = "<span style='color:Red;'>×</span>";
					}
					string value8 = "";
					if (dtInfo.Columns.Contains("AccountName"))
					{
						if (dataRow["AccountName"] != System.DBNull.Value)
						{
							value8 = dataRow["AccountName"].ToString();
						}
					}
					dataRow2["AccountName"] = value8;
					string value9 = "";
					if (dtInfo.Columns.Contains("AccountDate"))
					{
						if (dataRow["AccountDate"] != System.DBNull.Value)
						{
							value9 = dataRow["AccountDate"].ToString();
						}
					}
					dataRow2["AccountDate"] = value9;
					string a4 = "";
					if (dataRow["IsCashier"] != System.DBNull.Value)
					{
						a4 = dataRow["IsCashier"].ToString().ToLower().Trim();
					}
					if (a4 == "true" || a4 == "1")
					{
						dataRow2["IsCashier"] = "<span style='color:Green;'>√</span>";
					}
					else
					{
						dataRow2["IsCashier"] = "<span style='color:Red;'>×</span>";
					}
					string value10 = "";
					if (dtInfo.Columns.Contains("CashierName"))
					{
						if (dataRow["CashierName"] != System.DBNull.Value)
						{
							value10 = dataRow["CashierName"].ToString();
						}
					}
					dataRow2["CashierName"] = value10;
					string value11 = "";
					if (dtInfo.Columns.Contains("CashierDate"))
					{
						if (dataRow["CashierDate"] != System.DBNull.Value)
						{
							value11 = dataRow["CashierDate"].ToString();
						}
					}
					dataRow2["CashierDate"] = value11;
					string value12 = "";
					if (dtInfo.Columns.Contains("OwnerID"))
					{
						if (dataRow["OwnerID"] != System.DBNull.Value)
						{
							value12 = dataRow["OwnerID"].ToString();
						}
					}
					dataRow2["OwnerID"] = value12;
					string value13 = "";
					if (dtInfo.Columns.Contains("OwnerName"))
					{
						if (dataRow["OwnerName"] != System.DBNull.Value)
						{
							value13 = dataRow["OwnerName"].ToString();
						}
					}
					dataRow2["OwnerName"] = value13;
				}
				else
				{
					dataRow2["AccountAoucherID"] = "";
					dataRow2["AccountANumber"] = "";
					dataRow2["InputDate"] = "";
					dataRow2["UpdateDate"] = "";
					dataRow2["StockOrderID"] = "";
					dataRow2["AccountACount"] = "";
					dataRow2["AccountAExplain"] = "";
					dataRow2["Inputer"] = "";
					dataRow2["IsCaudit"] = "";
					dataRow2["CauditName"] = "";
					dataRow2["CauditDate"] = "";
					dataRow2["IsAccount"] = "";
					dataRow2["AccountName"] = "";
					dataRow2["AccountDate"] = "";
					dataRow2["IsCashier"] = "";
					dataRow2["CashierName"] = "";
					dataRow2["CashierDate"] = "";
					dataRow2["OwnerID"] = "";
					dataRow2["OwnerName"] = "";
				}
				a = text;
				int num2 = 0;
				if (dtInfo.Columns.Contains("AccountAItemID"))
				{
					if (dataRow["AccountAItemID"] != System.DBNull.Value)
					{
						num2 = dataRow["AccountAItemID"].ToInt32(new int[0]);
					}
				}
				dataRow2["AccountAItemID"] = num2;
				int num3 = 0;
				if (dtInfo.Columns.Contains("AAItemAccountSID"))
				{
					if (dataRow["AAItemAccountSID"] != System.DBNull.Value)
					{
						num3 = dataRow["AAItemAccountSID"].ToInt32(new int[0]);
					}
				}
				dataRow2["AAItemAccountSID"] = num3;
				dataRow2["AAItemSummary"] = dataRow["AAItemSummary"].ToString();
				dataRow2["AccountSNumber"] = dataRow["AccountSNumber"].ToString();
				if (subjectNameSign)
				{
					dataRow2["AccountSName"] = BLLInstance.BllAccountSubject.Display_ParentName(num3);
				}
				else
				{
					dataRow2["AccountSName"] = dataRow["AccountSName"].ToString();
				}
				string value14 = dataRow["BorrowPrice"].ToString();
				string value15 = dataRow["LoanPrice"].ToString();
				if (System.Convert.ToDecimal(value14) > 0m && System.Convert.ToDecimal(value15) == 0m)
				{
					dataRow2["BorrowPrice"] = value14;
					dataRow2["LoanPrice"] = "";
				}
				else
				{
					if (System.Convert.ToDecimal(value14) == 0m && System.Convert.ToDecimal(value15) > 0m)
					{
						dataRow2["BorrowPrice"] = "";
						dataRow2["LoanPrice"] = value15;
					}
				}
				dataTable.Rows.Add(dataRow2);
				num++;
			}
			return new DataSet
			{
				Tables = 
				{
					dataTable
				}
			};
		}
	}
}
